package com.gosophia.commons.persistence.test.unit;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;

import junit.framework.Assert;

import org.hibernate.EntityMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.transaction.TransactionConfiguration;

import com.gosophia.commons.DateTranslate;
import com.gosophia.commons.OrderCondition;
import com.gosophia.commons.Page;
import com.gosophia.commons.PropertyFilter;
import com.gosophia.commons.PropertyFilter.OperatorType;
import com.gosophia.commons.exception.BusinessException;
import com.gosophia.commons.persistence.test.organizationManagement.dao.OrganizationDao;
import com.gosophia.commons.persistence.test.organizationManagement.dao.PositionDao;
import com.gosophia.commons.persistence.test.organizationManagement.dao.UserInfoDao;
import com.gosophia.commons.persistence.test.organizationManagement.entity.Organization;
import com.gosophia.commons.persistence.test.organizationManagement.entity.UserInfo;

@ContextConfiguration(locations = { "classpath:applicationContext-test.xml",
"classpath:moduleContext.xml" })
@TransactionConfiguration(defaultRollback = true)
public class UTBaseDao extends AbstractTransactionalJUnit4SpringContextTests {

    @Autowired
    private OrganizationDao organizationDao;

    @Autowired
    private PositionDao positonDao;
    
    @Autowired
    private SessionFactory sessionFactory;
    
    @Autowired
    private UserInfoDao userInfoDao;
    
    @Test
    public void test(){
    	Session session = sessionFactory.getCurrentSession();
    	
    	UserInfo userInfo = userInfoDao.get(1L);
    	
    	UserInfo userInfo1 = new UserInfo();
    	userInfo1.setUserInfoId(122222L);
    	
    	session.evict(session.load(UserInfo.class, 
    			sessionFactory.getClassMetadata(userInfo1.getClass()).getIdentifier(userInfo1,EntityMode.POJO)));
    	
    	System.out.println("done");
    	session.update(userInfo1);
//    	System.out.println();
    }

    @Test
    public void testSave() {
        int size = sessionFactory.getCurrentSession().createQuery(
                "from Organization org").list().size();
        Organization organization = new Organization();
        organization.setOrgCode("代码"
                + UUID.randomUUID().toString().substring(0, 6));
        organization.setOrgName("机构名称" + UUID.randomUUID().toString().substring(0,6));
        organizationDao.save(organization);
        sessionFactory.getCurrentSession().flush();
        Assert.assertEquals(size + 1, sessionFactory.getCurrentSession()
                .createQuery("from Organization org").list().size());
    }

    // 更新:update(final T entity)
    @Test
    public void testUpdate1() {
        String uuid = UUID.randomUUID().toString();
        Organization organization = (Organization) sessionFactory
                .getCurrentSession().get(Organization.class, 13L);
        organization.setOrgAddress(uuid);
        organizationDao.update(organization);
        sessionFactory.getCurrentSession().flush();
        organization = (Organization) sessionFactory.getCurrentSession().get(
                Organization.class, 13L);
        Assert.assertEquals(uuid, organization.getOrgAddress());

    }
    
    //更新:update(PK id, Long version, Map<String, Object> updatedParams)
    @Test
    public void testUpdate2(){
        Map<String,Object> update = new HashMap<String,Object>();
        update.put("orgAddress",UUID.randomUUID().toString());
        organizationDao.update(13L,1L ,update);
    }
    
    //delete(T entity)
    @Test
    public void testDelete1(){
        Organization org = new Organization(13L,1L);
        organizationDao.delete(org);
    }
    //delete(PK id
    @Test
    public void testDelete2(){
        positonDao.delete(19L);
    }
    
    //delete(final PK id, Long version)
    @Test 
    public void testDelete3(){
        organizationDao.delete(16L,1L);
    }
    
    //getAllByOrder(List<OrderCondition> orderConditons)
    @Test
    public void testGetAllByOrder(){
        List<OrderCondition> orderConditons = new ArrayList<OrderCondition>();
        OrderCondition order1  =new OrderCondition("orgAddress", false);
        orderConditons.add(order1);
        List<Organization> orgList = organizationDao.getAllByOrder(orderConditons);
        Assert.assertTrue(orgList.size() > 0);
    }
    
    @Test
    public void testGetAllByOperatorOrder(){
        List<OrderCondition> orderConditons = new ArrayList<OrderCondition>();
        OrderCondition order1  = new OrderCondition("${orgId} - ${version}", true);
        orderConditons.add(order1);
        List<Organization> orgList = organizationDao.getAllByOrder(orderConditons);
        Assert.assertTrue(orgList.size() > 0);
    }
    
    //getByProperty(final String propertyName, final Object value)
    @Test
    public void testGetByProperty(){
        List<Organization> orgList = organizationDao.getByProperty("orgAddress", "地址3");
        Assert.assertEquals(1, orgList.size());
    }
    @Test
    public void testGetByPropertyDate(){
        List<UserInfo> orgList = userInfoDao.getByProperty("userBirthday", DateTranslate.simpleStringToDate("2010-09-25"));
        Assert.assertEquals(4, orgList.size());
    }
    
    @Test
    public void testGetByDateProperties(){
    	List<PropertyFilter> pfs = new ArrayList<PropertyFilter>();
    	pfs.add(new PropertyFilter("userBirthday", DateTranslate.simpleStringToDate("2010-09-25")));
        Page<UserInfo> page = new Page<UserInfo>();
        page =userInfoDao.getPageByProperties(page, pfs);
        Assert.assertEquals(4, page.getTotalCount());
    }
    
    //getByProperties(Map<String, Object> properties)
    @Test
    public void testGetByProperties(){
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("orgAddress", "地址3");
        properties.put("orgName", "机构名称3");
        List<Organization> orgList = organizationDao.getByProperties(properties);
        Assert.assertEquals(1, orgList.size());
    }
    
    //getUniqueByProperty(final String propertyName, final Object value)
    @Test
    public void testGetUniqueByProperty(){
        Organization org = organizationDao.getUniqueByProperty("orgName", "机构名称3");
        Assert.assertEquals("地址3", org.getOrgAddress());
        //Organization org = organizationDao.getUniqueByProperty("principal1Name", "负责人");若结果有多个，则报错，如何处理？？
    }
    // Page<T> getPage(Page<T> page)
    @Test
    public void testGetPage(){
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        Page<Organization> resultPage = organizationDao.getPage(page);
        Assert.assertEquals(2, resultPage.getNextPage());
        Assert.assertTrue(resultPage.getTotalPages() > 0);
        Assert.assertEquals(1, resultPage.getPrePage());
        Assert.assertTrue(resultPage.getTotalCount() > 0);
    }
    
 // Page<T> getPage(Page<T> page)
    @Test
    public void testGetPageOrderCon(){
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        Page<Organization> resultPage = organizationDao.getPage(page, 
                new OrderCondition("orgCode", true),
                new OrderCondition("version", false));
        
        String oldCode = null;
        Long version = null;
        for (Organization org : resultPage.getResult() ){
            if (oldCode != null) Assert.assertTrue( oldCode.hashCode() <= org.getOrgCode().hashCode());
            if (version != null) Assert.assertTrue( version >= org.getVersion());
            
            oldCode = org.getOrgCode();
            version = org.getVersion();
        }
    }
    
    
    //getPageByProperties(final Page<T> page,final List<PropertyFilter> propertyFilters)
    @Test
    public void testGetPageByProperties(){
       
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        
        PropertyFilter propertyFilter = new PropertyFilter();
        propertyFilter.setPropertyName("orgName");
        propertyFilter.setPropertyValue("工商局");
        
        propertyFilters.add(propertyFilter);
        
        PropertyFilter propertyFilter1 = new PropertyFilter();
        propertyFilter1.setPropertyName("positionList.positionName");
        propertyFilter1.setOperator(OperatorType.LIKE);
        propertyFilter1.setPropertyValue("");
        
        propertyFilters.add(propertyFilter1);
        
        Page<Organization> resultPage = organizationDao.getPageByProperties(page, propertyFilters);
        Assert.assertEquals(1, resultPage.getTotalCount());
    }
    
  //getPageByProperties(final Page<T> page,final List<PropertyFilter> propertyFilters)
    @Test
    public void testGetPageByPropertiesOrderCon(){
       
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        
        PropertyFilter propertyFilter = new PropertyFilter();
        propertyFilter.setPropertyName("orgName");
        propertyFilter.setPropertyValue("工商局");
        
        propertyFilters.add(propertyFilter);
        
        Page<Organization> resultPage = organizationDao.getPageByProperties(page, propertyFilters, 
                new OrderCondition("positionList.positionName", true),
                new OrderCondition("version", false));
        
        String oldCode = null;
        Long version = null;
        for (Organization org : resultPage.getResult() ){
            if (oldCode != null) Assert.assertTrue( oldCode.hashCode() <= org.getOrgCode().hashCode());
            if (version != null) Assert.assertTrue( version >= org.getVersion());
            
            oldCode = org.getOrgCode();
            version = org.getVersion();
        }
    }
    
    @Test
    public void testGetPageByPropertiesDateOrderCon(){
       
        Page<UserInfo> page = new Page<UserInfo>();
        page.setPageNo(1);
        page.setPageSize(10);
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        
        PropertyFilter propertyFilter = new PropertyFilter();
        propertyFilter.setPropertyName("userBirthday");
        propertyFilter.setPropertyValue(new Date());
        propertyFilter.setOperator(OperatorType.LT);
        
        propertyFilters.add(propertyFilter);
        
        Page<UserInfo> resultPage = userInfoDao.getPageByProperties(page, propertyFilters,
                new OrderCondition("userBirthday", true),
                new OrderCondition("version", false));
        
        Date birth = null;
        Long version = null;
        for (UserInfo user : resultPage.getResult() ){
            Date birth1 = user.getUserBirthday();
            if (birth != null && birth1!=null) Assert.assertTrue( !birth.after(user.getUserBirthday()));
            if (version != null) Assert.assertTrue( version >= user.getVersion());
            
            birth = user.getUserBirthday();
            version = user.getVersion();
        }
    }
    
    @Test
    public void testGetPageByPropertiesDate(){
       
        Page<UserInfo> page = new Page<UserInfo>();
        page.setPageNo(1);
        page.setPageSize(10);
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        
        PropertyFilter propertyFilter = new PropertyFilter();
        propertyFilter.setPropertyName("userBirthday");
        propertyFilter.setPropertyValue(new Date());
        propertyFilter.setOperator(OperatorType.LT);
        
        propertyFilters.add(propertyFilter);
        
        Page<UserInfo> resultPage = userInfoDao.getPageByProperties(page, propertyFilters);
        Assert.assertEquals(4, resultPage.getTotalCount());
    }
    @Test
    public void testGetPageByPropertiesTwoDate(){
       
        Page<UserInfo> page = new Page<UserInfo>();
        page.setPageNo(1);
        page.setPageSize(10);
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        
        PropertyFilter propertyFilter = new PropertyFilter("userBirthday",OperatorType.BETWEEN,
                DateTranslate.simpleStringToDate("2010-09-01"),DateTranslate.simpleStringToDate("2010-09-28"));
        PropertyFilter propertyFilter1 = new PropertyFilter();
        propertyFilter1.setPropertyName("userBirthday");
        propertyFilter1.setPropertyValue(DateTranslate.simpleStringToDate("2010-09-01"));
        propertyFilter1.setPropertyValue1(DateTranslate.simpleStringToDate("2010-09-28"));
        propertyFilter1.setOperator(OperatorType.BETWEEN);
        propertyFilter1.setPropertyValueType("date");
        
        propertyFilters.add(propertyFilter);
        
        Page<UserInfo> resultPage = userInfoDao.getPageByProperties(page, propertyFilters);
        Assert.assertEquals(4, resultPage.getTotalCount());
    }
    
    
    //getPageByProperties(Page<T> page,List<PropertyFilter> propertyFilters,List<OrderCondition> orderConditions)
    @Test
    public void testGetPageByProperties1(){
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        PropertyFilter propertyFilter = new PropertyFilter();
        propertyFilter.setPropertyName("orgName");
        propertyFilter.setPropertyValue("局");
        propertyFilter.setOperator(OperatorType.LIKE);
        propertyFilters.add(propertyFilter);
        
        List<OrderCondition> orderConditions = new ArrayList<OrderCondition>();
        OrderCondition orderCondtion = new OrderCondition("orgCode", true);
        orderConditions.add(orderCondtion);
        
        Page<Organization> resultPage = organizationDao.getPageByProperties(page, propertyFilters, orderConditions);
        Assert.assertTrue(resultPage.getTotalCount()>0);
        Assert.assertEquals("010", resultPage.getResult().get(0).getOrgCode());//测试排序
        Assert.assertEquals("014", resultPage.getResult().get(2).getOrgCode());
    }
    //getByIds(List<PK> ids)
    @Test
    public void testGetByIds(){
        List<Long> ids = new ArrayList<Long>();
        ids.add(1L);
        ids.add(12L);
        List<Organization> list = organizationDao.getByIds(ids);
        Assert.assertEquals(2, list.size());
    }
    //get(PK id)
    @Test
    public void testGet(){
        Organization org = organizationDao.get(1L);
        Assert.assertEquals("民政局", org.getOrgName());
    }
    //getAll()
    @Test
    public void testGetAll(){
        List<Organization> list = organizationDao.getAll();
        Assert.assertTrue(list.size() > 0);
    }
    //getPageBySimpleSearching(Page<T> page, String searchStr, String dateFormat,OrderCondition... orderConditions)
    @Test
    public void testGetPageBySimpleSearching() throws BusinessException{
        //该方法要查询的实体属性至少有一个@ShowItem或者@SearchEnable标注的属性
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        
        String searchStr = "局";
        OrderCondition orderCondition = new OrderCondition("orgId", true);
        
        Page<Organization> resultPage =organizationDao.getPageBySimpleSearching(page, searchStr, orderCondition);
        Assert.assertTrue(resultPage.getTotalCount() > 0);
        
    }
    
    @Test
    public void testGetPageBySimpleSearchingWith_() throws BusinessException{
        //该方法要查询的实体属性至少有一个@ShowItem或者@SearchEnable标注的属性
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        
        String searchStr = "后_的";
        OrderCondition orderCondition = new OrderCondition("orgId", true);
        
        Page<Organization> resultPage =organizationDao.getPageBySimpleSearching(page, searchStr, orderCondition);
        Assert.assertTrue(resultPage.getTotalCount() > 0);
    }
    
    @Test
    public void testGetPageBySimpleSearchingByJoinSearchItem() throws BusinessException{
        //该方法要查询的实体属性至少有一个@SearchEnable、或JoinSearchItem标注的属性
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        
        String searchStr = "3";
        OrderCondition orderCondition = new OrderCondition("orgId", true);
        
        Page<Organization> resultPage =organizationDao.getPageBySimpleSearching(page, searchStr, orderCondition);
        Assert.assertTrue(resultPage.getTotalCount() > 0);
    }
    
    //countNamedQueryResult(final String queryName,final Map<String, Object> values)
    @Test
    public void testCountNamedQueryResult(){
        Map<String,Object> values = new HashMap<String,Object>();
        values.put("orgName", "民政局");
        long count = organizationDao.countNamedQueryResult("OrgManagement.countNamedQueryResult", values);
        Assert.assertEquals(1, count);
    }
    //countNamedQueryResult(final String queryName,final Object... values)
    @Test
    public void testCountNamedQueryResult1(){
        long count = organizationDao.countNamedQueryResult("OrgManagement.countNamedQueryResult1", "民政局");
        Assert.assertEquals(1, count);
    }
    //executeNamedQuery(String queryName, Object... values) 
    @Test
    public void testExecuteNamedQuery(){
        organizationDao.executeNamedQuery("OrgManagement.updateByOrgName","民政局修改","民政局");
        organizationDao.flush();
        Organization org = organizationDao.get(1L);
        Assert.assertEquals("民政局修改", org.getOrgName());
    }
    
    //executeNamedQuery(String queryName, Map<String, Object> values)
    @Test
    public void testExecuteNamedQuery1(){
        Map<String,Object> values = new HashMap<String,Object>();
        values.put("orgName", "民政局修改");
        values.put("orgName1", "民政局");
        organizationDao.executeNamedQuery("OrgManagement.updateByOrgName1", values);
        organizationDao.flush();
        Organization org = organizationDao.get(1L);
        Assert.assertEquals("民政局修改", org.getOrgName());
    }
    //findListByNamedQuery(String queryName, Object... values)
    @Test
    public void testFindListByNamedQuery(){
        List<Organization> list = organizationDao.getListByNamedQuery("OrgManagement.findByOrgName", "工商局");
        Assert.assertEquals(1, list.size());
    }
    //findListByNamedQuery(String queryName,Map<String, Object> values)
    @Test
    public void testFindListByNamedQuery1(){
        Map<String,Object> values = new HashMap<String,Object>();
        values.put("orgName", "工商局");
        
        List<Organization> list = organizationDao.getListByNamedQuery("OrgManagement.findByOrgNameNamed", values);
        Assert.assertEquals(1, list.size());
    }
    @Test
    public void testFindListByNamedQueryNoParam(){
        Map<String,Object> values = new HashMap<String,Object>();
        
        List<Organization> list = organizationDao.getListByNamedQuery("OrgManagement.findByOrgNameNamedNoParam", values);
        Assert.assertEquals(1, list.size());
    }
    //getPageByNamedQuery(Page<T> page, String queryName,Object... values)
    @Test
    public void testGetPageByNamedQuery(){
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        
        Page<Organization> resultPage = organizationDao.
                    getPageByNamedQuery(page, "OrgManagement.getPageByNamedQuery", "部门1");
        Assert.assertEquals(1, resultPage.getTotalCount());
        
    }
    //getPageByNamedQuery(Page<T> page, String queryName,Map<String, ?> values)
    @Test
    public void testGetPageByNamedQuery1(){
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        
        Map<String,Object> values = new HashMap<String,Object>();
        values.put("orgId", 1L);
        
        Page<Organization> resultPage = organizationDao.getPageByNamedQuery(page, "OrgManagement.getPageByNamedQuery1", values);
        Assert.assertEquals(1, resultPage.getTotalCount());
    }
    //getUniqueByNamedQuery(final String queryName,final Object... values)
    @Test
    public void testGetUniqueByNamedQuery(){
        Organization org = organizationDao.getUniqueByNamedQuery("OrgManagement.getUniqueByNamedQuery", 1L);
        Assert.assertEquals("民政局", org.getOrgName());
    }
    //getUniqueByNamedQuery(final String queryName,final Map<String, Object> values)
    @Test
    public void testGetUniqueByNamedQuery1(){
        Map<String,Object> values = new HashMap<String,Object>();
        values.put("orgId", 1L);
        
        Organization org = organizationDao.getUniqueByNamedQuery("OrgManagement.getUniqueByNamedQuery1", values);
        Assert.assertEquals("民政局", org.getOrgName());
    }
    
    @Test
    public void testPropertyFilterWithString(){
        
        Page<Organization> page = new Page<Organization>();
        page.setPageNo(1);
        page.setPageSize(10);
        
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        PropertyFilter propertyFilter = new PropertyFilter();
        propertyFilter.setPropertyName("orgName");
        propertyFilter.setPropertyValue("局");
        propertyFilter.setOperator(OperatorType.LIKE);
        propertyFilters.add(propertyFilter);
        
        List<OrderCondition> orderConditions = new ArrayList<OrderCondition>();
        OrderCondition orderCondtion = new OrderCondition("orgCode", true);
        orderConditions.add(orderCondtion);
        
        Page<Organization> resultPage = organizationDao.getPageByProperties(page, propertyFilters, orderConditions);
        Assert.assertTrue(resultPage.getTotalCount() > 0);
        Assert.assertEquals("010", resultPage.getResult().get(0).getOrgCode());//测试排序
        Assert.assertEquals("014", resultPage.getResult().get(2).getOrgCode());
    }
    
    @Test
    public void testPropertyFilterWithDate(){
        Page<UserInfo> page = new Page<UserInfo>();
        page.setPageNo(1);
        page.setPageSize(10);
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        
        PropertyFilter propertyFilter = new PropertyFilter("userBirthday",OperatorType.BETWEEN,
                DateTranslate.simpleStringToDate("2010-09-01"),DateTranslate.simpleStringToDate("2010-09-28"));
        PropertyFilter propertyFilter1 = new PropertyFilter();
        propertyFilter1.setPropertyName("userBirthday");
        propertyFilter1.setPropertyValue(DateTranslate.simpleStringToDate("2010-09-01"));
        propertyFilter1.setPropertyValue1(DateTranslate.simpleStringToDate("2010-09-28"));
        propertyFilter1.setOperator(OperatorType.BETWEEN);
        propertyFilter1.setPropertyValueType("date");
        
        propertyFilters.add(propertyFilter);
        
        Page<UserInfo> resultPage = userInfoDao.getPageByProperties(page, propertyFilters);
        Assert.assertEquals(4, resultPage.getTotalCount());
    }
    
    @Test
    public void testPropertyFilterWithLong(){
        Page<UserInfo> page = new Page<UserInfo>();
        page.setPageNo(1);
        page.setPageSize(10);
        List<PropertyFilter> propertyFilters = new ArrayList<PropertyFilter>();
        
        PropertyFilter propertyFilter1 = new PropertyFilter();
        propertyFilter1.setPropertyName("userInfoId");
        propertyFilter1.setPropertyValue(1L);
        propertyFilter1.setOperator(OperatorType.EQ);
        
        propertyFilters.add(propertyFilter1);
        
        Page<UserInfo> resultPage = userInfoDao.getPageByProperties(page, propertyFilters);
        Assert.assertEquals(1, resultPage.getTotalCount());
    }
    @Test
    public void testPropertyFilterWithSome(){
        PropertyFilter propertyFilter = new PropertyFilter();
        propertyFilter.setPropertyValue(12.35D);
        Double d = (Double) propertyFilter.getPropertyValue();
        Assert.assertEquals(12.35D, d);
        propertyFilter.setPropertyValue(true);
        Boolean b = (Boolean) propertyFilter.getPropertyValue();
        Assert.assertEquals(Boolean.TRUE, b);
        propertyFilter.setPropertyValue(10);
        Integer i = (Integer) propertyFilter.getPropertyValue();
        Assert.assertTrue(i == 10);
    }
    
    @Test
    public void myTest(){
    	String s = "${dddddd.ffdd}";
    	String regex = "\\$\\{[a-z A-Z]+[\\.[a-z A-Z]]*+\\}";
    	System.out.println(s.matches(regex));
    }
    
//    @Test
//    public void testHql(){
//    	String hql = "select distinct e from Organization e join e.positionList e0 " +
//    			" where  to_char(e.orgId) like '%局%'" +
//    			" or e.orgName like '%局%'" +
//    			" or e.orgAddress like '%局%'" +
//    			" or e.orgShortName like '%局%'" +
//    			" and  to_char(e0.positionName) like '%局%'" //+
////    			" and  to_char(e1.positionName) = ''" +
////    			" order by e1.positionName asc"
//    	;
//    	
//    	hql = "select count(*) from " + hql;
//    	
//    	System.out.println(organizationDao.getSession().createQuery(hql).);
//    }
}
